<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:general="http://java.sun.com/jsf/composite/components/general"
      >
    <ui:composition template="template.xhtml">
        <ui:define name="dialogs">

             <general:confirmDialog
                widgetDialog="confirmRemoveBankDialog"
                dialogTitle="Remoção de banco"
                message="Deseja remover o banco selecionado?"
                buttonYesAction="#{bankBean.delete()}"
                onclick_no_javascript="confirmRemoveBankDialog.hide()"
                onclick_yes_javascript="confirmRemoveBankDialog.hide()"
                onclick_yes_update=":bankListform :growl"/>


            <p:dialog header="Cadastro de banco" widgetVar="newBank" modal="true" resizable="false">
                <p:panel id="panelnewBank" header="Banco" style="width: 310px">

                    <h:form id="newBankform">
                          <h:panelGrid columns="2">
                            <h:outputText value="Numero: "  />
                            <p:inputText value="#{bankBean.bank.numeroBanco}"  style="width: 170px"/>
                            <h:outputText value="Nome: "  />
                            <p:inputText value="#{bankBean.bank.name}" style="width: 170px" />
                          </h:panelGrid>
                        <p:separator />
                        <p:commandButton value="Salvar" action="#{bankBean.save()}" update=":bankListform :growl" onclick="newBank.hide()" />
                    </h:form>

                </p:panel>
            </p:dialog>


             <p:dialog header="Editar banco" widgetVar="editBank" modal="true" resizable="false">
                <p:panel id="panelEditBank" header="Banco" style="width: 310px">

                    <h:form id="editBankform">
                          <h:panelGrid columns="2">
                            <h:outputText value="Numero: "  />
                            <p:inputText value="#{bankBean.bankSelected.numeroBanco}"  style="width: 170px"/>
                            <h:outputText value="Nome: "  />
                            <p:inputText value="#{bankBean.bankSelected.name}" style="width: 170px" />
                          </h:panelGrid>
                        <p:separator />
                        <p:commandButton value="Salvar" action="#{bankBean.edit()}" update=":bankListform :growl" onclick="editBank.hide()" />
                    </h:form>

                </p:panel>
            </p:dialog>

        </ui:define>


        <ui:define name="content">
            <h:form id="bankListform">
              <h:panelGrid columns="2">
                        <h:outputText value="Nome do banco:" styleClass="formLabel" style="width: 120px"/>
                        <p:inputText id="bancoName" style="width: 300px" value="#{bankBean.filterNameBank}"
                                     onclick="jQuery(this).select()">
                            <p:ajax event="keyup" update="bancoList" />
                        </p:inputText>

                        <p:watermark for="bancoName" value="Digite o nome do banco" />
                    </h:panelGrid>
              <h:panelGroup id="bancoList">
                  <p:dataTable var="bank" value="#{bankBean.listBank}"
                               paginator="true" rows="10" rowKey="#{bank.id}"
                                     emptyMessage="Nenhum banco foi encontrado"
                                     selectionMode="single" selection="#{bankBean.bankSelected}">

                            <p:ajax event="rowSelect" update="@this"/>

                            <f:facet name="header">
                                Lista de bancos
                            </f:facet>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Numero do banco" />
                                </f:facet>
                                <h:outputText value="#{bank.numeroBanco}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Nome" />
                                </f:facet>
                                <h:outputText value="#{bank.name}" />
                            </p:column>

                            <f:facet name="footer">
                                <p:commandButton icon="ui-icon ui-icon-plus" title="Adicionar banco" oncomplete="newBank.show()" update=":newBankform"
                                                 disabled="#{not sharedPermissionManagedBean.hasPermission('CRIAR_BANCO')}"/>
                                <p:commandButton icon="ui-icon ui-icon-pencil" title="Editar banco" update=":editBankform" oncomplete="editBank.show()"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('EDITAR_BANCO')) or (bankBean.bankSelected.id == null)}"/>

                                <p:commandButton icon="ui-icon ui-icon-minus" title="Remover banco" onclick="confirmRemoveBankDialog.show()"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('REMOVER_BANCO')) or (bankBean.bankSelected.id == null)}"/>

                            </f:facet>
                        </p:dataTable>
                    </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>


